const express = require('express')
const router = express.Router()
const database = require('../db/goods')
//查询商品数据
router.get('/api/goods/shopList',(req,res)=>{
    let searchValue = req.query.searchValue
    var reg = new RegExp(searchValue)
    var key,rule
    if(req.query.orderBy){
        key = req.query.orderBy.key
        rule = req.query.orderBy.rule
    }
    database.find({name:reg}).then(data=>{
        //商品价格,销量排序
        if(key){
            //升序
            if(rule == 'asc'){
                data.sort(function(a,b){
                    return b[key] - a[key]
                })
            }else{
                //降序
                data.sort(function(a,b){
                    return a[key] - b[key]
                })
            }
        }
        //返回默认内容
        return res.send({
            code:0,
            data
        })
    })
    
})
//首页推荐
router.get('/api/index_list/0/data/1',(req,res)=>{
    res.send({
        code:0,
        data:{
            topBar:[
                {id:0,label:'推荐'},
                {id:1,label:'大红袍'},
                {id:2,label:'绿茶'},
                {id:3,label:'铁观音'},
                {id:4,label:'普洱'},
                {id:5,label:'茶具'},
                {id:6,label:'花茶'}
            ],
            data:[
                {
                    id:0,
                    type:'swiperList',
                    data:[
                        {id:0,imgUrl:'./images/swiper1.jpeg'},
                        {id:1,imgUrl:'./images/swiper2.jpeg'},
                        {id:2,imgUrl:'./images/swiper3.jpeg'}
                    ]
                },
                {
                    id:1,
                    type:'icons',
                    data:[
                        {
                            id:1,
                            title:'自饮茶',
                            imgUrl:'./images/icons1.png'
                        },
                        {
                            id:2,
                            title:'茶具',
                            imgUrl:'./images/icons2.png'
                        },
                        {
                            id:3,
                            title:'茶礼盒',
                            imgUrl:'./images/icons3.png'
                        },
                        {
                            id:4,
                            title:'领福利',
                            imgUrl:'./images/icons4.png'
                        },
                        {
                            id:5,
                            title:'官方验证',
                            imgUrl:'./images/icons5.png'
                        }
                    ]
                },
                //爆款推荐
                {
                    id:2,
                    type:'RecommendList',
                    data:[
                        {
                            id:1,
                            name:'龙井1号铁罐250g',
                            content:'鲜爽甘醇 口粮首选',
                            price:'68',
                            imgUrl:'./images/recommend.jpeg'
                        },
                        {
                            id:1,
                            name:'龙井1号铁罐250g',
                            content:'鲜爽甘醇 口粮首选',
                            price:'68',
                            imgUrl:'./images/recommend.jpeg'
                        }
                    ]
                },
                //猜你喜欢
                {
                    id:3,
                    type:'likeList',
                    data:[
                        {
                            id:1,
                            imgUrl:'/images/goods1.jpg',
                            name:'2022春茶明前龙井飞花',
                            price:'238'
                        },
                        {
                            id:4,
                            imgUrl:'/images/goods4.jpg',
                            name:'绿茶-竹影清风碧螺春',
                            price:'118'
                        },
                        {
                            id:3,
                            imgUrl:'/images/goods3.jpg',
                            name:'黄山太平猴魁绿茶1号',
                            price:'299'
                        },
                        {
                            id:4,
                            imgUrl:'/images/goods4.jpg',
                            name:'绿茶-竹影清风碧螺春',
                            price:'118'
                        },
                        {
                            id:3,
                            imgUrl:'/images/goods3.jpg',
                            name:'黄山太平猴魁绿茶1号',
                            price:'299'
                        },
                        {
                            id:2,
                            imgUrl:'/images/goods2.jpg',
                            name:'历史名茶黄山毛峰1号',
                            price:'256'
                        },
                        {
                            id:3,
                            imgUrl:'/images/goods3.jpg',
                            name:'黄山太平猴魁绿茶1号',
                            price:'299'
                        },
                        {
                            id:4,
                            imgUrl:'/images/goods4.jpg',
                            name:'绿茶-竹影清风碧螺春',
                            price:'118'
                        },
                        {
                            id:2,
                            imgUrl:'/images/goods2.jpg',
                            name:'历史名茶黄山毛峰1号',
                            price:'256'
                        },
                        {
                            id:4,
                            imgUrl:'/images/goods4.jpg',
                            name:'绿茶-竹影清风碧螺春',
                            price:'118'
                        },
                    ]
                }
            ]
        }
    })
})
//首页大红袍
router.get('/api/index_list/1/data/1',(req,res)=>{
    res.send({
        code:1,
        data:[
            {
                id:1,
                type:'adList',
                data:[
                    {
                        id:1,
                        imgUrl:'./images/dhp.jpeg'
                    },
                    {
                        id:2,
                        imgUrl:'./images/dhp.jpeg'
                    }
                ]
            },
            {
                id:2,
                type:'likeList',
                data:[
                    {
                        id:1,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    },
                    {
                        id:2,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    },
                    {
                        id:3,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    }
                ]
            }
        ]
    })
})
//首页铁观音
router.get('/api/index_list/2/data/1',(req,res)=>{
    res.send({
        code:2,
        data:[
            {
                id:1,
                type:'adList',
                data:[
                    {
                        id:1,
                        imgUrl:'./images/tgy.jpeg'
                    },
                    {
                        id:2,
                        imgUrl:'./images/tgy.jpeg'
                    }
                ]
            },
            {
                id:2,
                type:'likeList',
                data:[
                    {
                        id:1,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    },
                    {
                        id:2,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    },
                    {
                        id:3,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    }
                ]
            }
        ]
    })
})
//首页铁观音
router.get('/api/index_list/3/data/1',(req,res)=>{
    res.send({
        code:3,
        data:[
            {
                id:1,
                type:'adList',
                data:[
                    {
                        id:1,
                        imgUrl:'./images/tgy.jpeg'
                    },
                    {
                        id:2,
                        imgUrl:'./images/tgy.jpeg'
                    }
                ]
            },
            {
                id:2,
                type:'likeList',
                data:[
                    {
                        id:1,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    },
                    {
                        id:2,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    },
                    {
                        id:3,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    }
                ]
            }
        ]
    })
})
//首页铁观音
router.get('/api/index_list/4/data/1',(req,res)=>{
    res.send({
        code:4,
        data:[
            {
                id:1,
                type:'adList',
                data:[
                    {
                        id:1,
                        imgUrl:'./images/tgy.jpeg'
                    },
                    {
                        id:2,
                        imgUrl:'./images/tgy.jpeg'
                    }
                ]
            },
            {
                id:2,
                type:'likeList',
                data:[
                    {
                        id:1,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    },
                    {
                        id:2,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    },
                    {
                        id:3,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    }
                ]
            }
        ]
    })
})
//首页铁观音
router.get('/api/index_list/5/data/1',(req,res)=>{
    res.send({
        code:5,
        data:[
            {
                id:1,
                type:'adList',
                data:[
                    {
                        id:1,
                        imgUrl:'./images/tgy.jpeg'
                    },
                    {
                        id:2,
                        imgUrl:'./images/tgy.jpeg'
                    }
                ]
            },
            {
                id:2,
                type:'likeList',
                data:[
                    {
                        id:1,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    },
                    {
                        id:2,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    },
                    {
                        id:3,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    }
                ]
            }
        ]
    })
})
//首页铁观音
router.get('/api/index_list/6/data/1',(req,res)=>{
    res.send({
        code:6,
        data:[
            {
                id:1,
                type:'adList',
                data:[
                    {
                        id:1,
                        imgUrl:'./images/tgy.jpeg'
                    },
                    {
                        id:2,
                        imgUrl:'./images/tgy.jpeg'
                    }
                ]
            },
            {
                id:2,
                type:'likeList',
                data:[
                    {
                        id:1,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    },
                    {
                        id:2,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    },
                    {
                        id:3,
                        imgUrl:'./images/like.jpeg',
                        name:'建盏茶具套装 红色芝麻毫 12件套',
                        price:'299'
                    }
                ]
            }
        ]
    })
})

module.exports = router